{% extends "admin/base.html" %}

{% block content %}
<div class="card">
    <div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
        <h2>静态网页管理</h2>
        <div>
            <button type="button" class="btn btn-danger" id="batchDeleteBtn" disabled style="margin-right: 10px;">批量删除</button>
            <a href="/admin/static-pages/add" class="btn btn-primary">添加静态网页</a>
        </div>
    </div>
    <div class="card-body">
        {% if pages %}
        <form id="batchDeleteForm" action="/admin/static-pages/batch-delete" method="post">
        <table class="table">
            <thead>
                <tr>
                    <th>
                        <input type="checkbox" id="selectAll">
                    </th>
                    <th>ID</th>
                    <th>名称</th>
                    <th>目录</th>
                    <th>访问地址</th>
                    <th>描述</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for page in pages %}
                <tr>
                    <td>
                        <input type="checkbox" name="page_ids" value="{{ page.id }}" class="page-checkbox">
                    </td>
                    <td>{{ page.id }}</td>
                    <td>{{ page.name }}</td>
                    <td>{{ page.directory }}</td>
                    <td>
                        <a href="/pages/{{ page.directory }}" target="_blank" class="text-primary">/pages/{{ page.directory }}</a>
                    </td>
                    <td>{{ page.description[:50] }}{% if page.description|length > 50 %}...{% endif %}</td>
                    <td>
                        {% if page.status %}
                        <span style="color: #2ecc71;">启用</span>
                        {% else %}
                        <span style="color: #e74c3c;">禁用</span>
                        {% endif %}
                        <button type="button" class="btn btn-xs {% if page.status %}btn-warning{% else %}btn-success{% endif %} toggle-status-btn" data-id="{{ page.id }}" data-status="{{ page.status }}" style="margin-left: 5px;">
                            {% if page.status %}禁用{% else %}启用{% endif %}
                        </button>
                    </td>
                    <td>
                        <button type="button" class="btn btn-xs btn-info file-btn bg-primary" data-id="{{ page.id }}">文件管理</button>
                        <a href="/admin/static-pages/edit/{{ page.id }}" class="btn btn-secondary btn-sm mr-2" style="margin-left: 5px;">编辑</a>
                        <button type="button" class="btn btn-xs btn-danger delete-btn" data-id="{{ page.id }}" data-name="{{ page.name }}" style="margin-left: 5px;">删除</button>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        </form>

        <!-- 分页控件 -->
        <div class="pagination-container mt-3 text-right">
            <div class="btn-group d-inline-block">
                {% if current_page == 1 %}
                <button class="btn btn-default btn-sm disabled" disabled>首页</button>
                <button class="btn btn-default btn-sm disabled" disabled>上一页</button>
                {% else %}
                <a href="/admin/static-pages?page={{ 1 }}" 
                   class="btn btn-default btn-sm">
                    首页
                </a>
                <a href="/admin/static-pages?page={{ current_page - 1 }}" 
                   class="btn btn-default btn-sm">
                    上一页
                </a>
                {% endif %}
                {% for i in range(1, total_pages + 1) %}
                    {% if i == current_page %}
                        <a href="/admin/static-pages?page={{ i }}" 
                           class="btn btn-primary btn-sm">{{ i }}</a>
                    {% else %}
                        <a href="/admin/static-pages?page={{ i }}" 
                           class="btn btn-default btn-sm">{{ i }}</a>
                    {% endif %}
                {% endfor %}
                {% if current_page == total_pages %}
                <button class="btn btn-default btn-sm disabled" disabled>下一页</button>
                <button class="btn btn-default btn-sm disabled" disabled>末页</button>
                {% else %}
                <a href="/admin/static-pages?page={{ current_page + 1 }}" 
                   class="btn btn-default btn-sm">
                    下一页
                </a>
                <a href="/admin/static-pages?page={{ total_pages }}" 
                   class="btn btn-default btn-sm">
                    末页
                </a>
                {% endif %}
            </div>
        </div>

        {% else %}
        <p>暂无静态网页数据</p>
        {% endif %}
        
        <!-- 引入静态页面管理相关脚本 -->
        <script src="/static/js/admin/static-pages-list.js"></script>
        

    </div>
</div>
{% endblock %}